package cn.pzhu.controller.admin;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.Role;
import cn.pzhu.model.User;
import cn.pzhu.services.admin.RoleServices;

import java.util.List;

/**
 * Created by dongp on 2016/4/25.
 */
public class RoleController extends BaseController {

    private RoleServices roleServices = new RoleServices();

    public void index() {
        render("role.jsp");
    }

    public void ajaxQuery() {
        List<Role> roles = roleServices.ajaxQuery();
        renderJson(roles);
    }

    public void ajaxQueryPage() {
        String pageNumber = getPara("pageNumber");
        String pageSize = getPara("pageSize");
        String search = getPara("search","");
        List atrrs = roleServices.ajaxQueryPage(pageNumber, pageSize, search);
        renderJson(atrrs);
    }

    public void ajaxUpdate() {
        String roleID = getPara("roleID");
        String roleName = getPara("roleName");
        Integer roleValue = getParaToInt("roleValue", 0);

        boolean result = roleServices.ajaxUpdate(roleID, roleName, roleValue);
        if(result) {
            setAttr("msg","success");// 该返回的成功信息前台暂时没用
        }else {
            setAttr("msg","failue");
        }

        render("role.jsp");
    }

    public void ajaxAdd() {
        String roleName = getPara("roleName");
        Integer roleValue = getParaToInt("roleValue",10);

        boolean result = roleServices.ajaxAdd(roleName, roleValue);
        render("role.jsp");
    }

    public void ajaxDel() {
        String roleID = getPara("roleID");
        boolean result = roleServices.ajaxDel(roleID);

        render("role.jsp");
    }

}
